package com.hand.wyc24548.app.service.impl;

import com.hand.wyc24548.domain.repository.SoLineRepository;
import io.choerodon.core.exception.CommonException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hand.wyc24548.app.service.SoLineService;
import com.hand.wyc24548.domain.entity.SoLine;

/**
 * @Author wangyc
 * @create 2019/8/9 15:07
 */

@Service
public class SoLineServiceImpl implements SoLineService {

    @Autowired
    private SoLineRepository soLineRepository;

    /**
     * 新增订单行
     * @param soLine
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public SoLine create(SoLine soLine) {
        soLineRepository.insert(soLine);
        return soLine;
    }

    /**
     * 更新订单行
     * @param soLine
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public SoLine update(SoLine soLine) {
        SoLine soLine1=soLineRepository.selectByPrimaryKey(soLine);
        if (soLine1==null){
            throw new CommonException("hodr.so.line.notFound");
        }
        soLineRepository.updateByPrimaryKey(soLine);
        return soLine;
    }

    /**
     * 根据订单行ID删除订单行信息
     * @param soLineId
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Long soLineId) {
        SoLine soLine=new SoLine();
        soLine.setSoLineId(soLineId);
        soLineRepository.delete(soLine);
    }
}
